package com.wceManage.services.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wceManage.beans.ECourse;
import com.wceManage.beans.JCours;
import com.wceManage.beans.page.PageList;
import com.wceManage.data.mapper.BaseMapper;
import com.wceManage.data.mapper.ECourseMapper;
import com.wceManage.services.ECourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jiangwei
 * @since 20/5/8
 */
@Service
public class ECourseServiceImpl extends BaseServiceImpl<ECourse> implements ECourseService{

    @Autowired(required = false)
    private ECourseMapper courseMapper;

    @Override
    public BaseMapper<ECourse> getMapper() {
        return courseMapper;
    }

    @Override
    public void save(ECourse eCourse) {
        courseMapper.insert(eCourse);
    }

    @Override
    public List<JCours> findAll(ECourse course2) {
        return courseMapper.findAll(course2);
    }

    @Override
    public PageList queryPage(PageList pageList, ECourse course) {
        Page<ECourse> page;
        int pageStart;
        if (pageList.getiDisplayLength() == -1) {//不分页
            pageStart = 1;
            page = PageHelper.startPage(pageStart, 10000, false);
        } else {
            pageStart = pageList.getiDisplayStart() / pageList.getiDisplayLength() + 1;
            page = PageHelper.startPage(pageStart, pageList.getiDisplayLength());
        }
        getMapper().queryList(course);
        pageList.setiTotalRecords(page.getTotal());
        pageList.setiTotalDisplayRecords(pageList.getiTotalRecords());
        pageList.setAaData(page.getResult());
        return pageList;
    }

    @Override
    public Integer updateStatus(ECourse course) {
        return courseMapper.updateStatus(course);
    }

    @Override
    public void QRCodeSave(HashMap<String, Object> map) {
        courseMapper.QRCodeSave(map);
    }

    @Override
    public List<Map> queryQRCode() {
        return courseMapper.queryQRCode();
    }

    @Override
    public void deleteCode(String codeId) {
        courseMapper.deleteCode(codeId);
    }
}
